package org.example.json.enumeration;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class ColorEnumSerializer extends JsonSerializer<Color> {
    @Override
    public void serialize(Color item, JsonGenerator g, SerializerProvider serializers) throws IOException {
        if (serializers.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)) {
            g.writeString(item.toString());
        } else {
            g.writeNumber(item.getValue());
        }
    }
}